package com.hualan.controller;

import com.hualan.domain.Consultproblem;
import com.hualan.domain.Teacher;
import com.hualan.service.ConsultProblemService;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Consultproblem")
public class ConsultproblemController {
    @Autowired
    public ConsultProblemService consultProblemService;

    @PostMapping("/selectAllProblemAndReply")
    public R selectAllProblemAndReply(int userId){
        List<Consultproblem> list=consultProblemService.selectAllReply(userId);
        if (list==null){
            return R.fail(200);
        }else {
            return R.success(list);
        }
    }


    @GetMapping("/problems/show")
    public R selectAll(){
        List<Consultproblem> consultproblemList= consultProblemService.selectAll();
        if (consultproblemList.size()>0){
            return R.success(consultproblemList);
        }else {
            return R.fail(consultproblemList);
        }
    }

    @GetMapping("/problems/select")
    public R selectAlllike(String title) {
        List<Consultproblem> consultproblemList= consultProblemService.selectAlllike(title);
        if (consultproblemList.size()>0){
            return R.success(consultproblemList);
        }else {
            return R.fail(consultproblemList);
        }
    }

    @PostMapping("/problems/insert")
    public R insertSelective(Consultproblem record){
        int i = consultProblemService.insertSelective(record);
        if(i>0){
            return R.success(i);
        }else{
            return R.fail(i);
        }
    }

    @PutMapping("/problems/update")
    public R updateByPrimaryKeySelective(Consultproblem record){
        int i=consultProblemService.updateByPrimaryKeySelective(record);
        if(i>0){
            return R.success(i);
        }else{
            return R.fail(i);
        }
    }

    @DeleteMapping("/problems/delete")
    public R deleteByPrimaryKey(Long id){
        int i=consultProblemService.deleteByPrimaryKey(id);
        if(i>0){
            return R.success(i);
        }else{
            return R.fail(i);
        }
    }


    @GetMapping("/problems/selectIdTitle")
    public R selectAllIdProblemtitle(){
        List<Consultproblem> consultproblemList = consultProblemService.selectAllIdProblemtitle();
        if (consultproblemList.size()>0){
            return R.success(consultproblemList);
        }else {
            return R.fail(consultproblemList);
        }
    }

}
